﻿using System;
using System.Web.Mvc;

using Whoever.Framework.Utils;
using Whoever.Framework.CustomException;
using Whoever.Patterns.MVC.Filters;
using Whoever.Patterns.MVC.Models;

using EditorialProyectos.Website.Models;
using EditorialProyectos.Business;
using EditorialProyectos.Business.Entities;

using Whoever.Framework.Enum;

namespace EditorialProyectos.Website.Controllers
{
    public class BenefitController : Controller
    {

        public ActionResult Main()
        {
            return View();
        }


        [AJAXExceptionHandler]
        public ActionResult Create(Benefit entity)
        {
            try
            {
                //entity.User = SessionState.LoggedInUser;
                if (ModelState.IsValid)
                {
                    var id = ManagerFactory.BenefitManager.Insert(entity);
                    return Json(new AJAXResponse { Message = Localized.Message("Create", MessageType.Success), MessageType = MessageType.Success, Success = true, MustRedirect = false, ExtraData = new { id = id } });
                }
                throw new BusinessException(Localized.Message("Model", MessageType.Error));
            }
            catch (BusinessException ex)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new Exception(Localized.Message("Exception", MessageType.Error));
            }
        }

        public ActionResult GetPartial(string partialName)
        {
            var model = new BenefitViewModel();

            ManagerFactory.BenefitManager.FillSelectablesRelations(model);

            return PartialView(partialName, model);
        }
    //    public ActionResult Main()
    //    {
    //        var BenefitViewModel = new BenefitViewModel();

    //        ManagerFactory.BenefitManager.FillSelectablesRelations(BenefitViewModel);

    //        BenefitViewModel.List = ManagerFactory.BenefitManager.GetAll();

    //        return View(BenefitViewModel);
    //    }

    //    [AJAXExceptionHandler]
    //    public ActionResult RebindList()
    //    {
    //        return Json(ManagerFactory.BenefitManager.GetAll());
    //    }

    //    [AJAXExceptionHandler]
    //    public ActionResult Create(Benefit entity)
    //    {
    //        try
    //        {
    //            if (ModelState.IsValid)
    //            {
    //                ManagerFactory.BenefitManager.Insert(entity);

    //                return Json(new AJAXResponse { Message = Localized.Message("Create", MessageType.Success), Success = true, MustRedirect = false });
    //            }
    //            throw new BusinessException(Localized.Message("Model", MessageType.Error));
    //        }
    //        catch (BusinessException ex)
    //        {
    //            throw;
    //        }
    //        catch (Exception ex)
    //        {
    //            throw new Exception(Localized.Message("Exception", MessageType.Error));
    //        }
    //    }

    //    [AJAXExceptionHandler]
    //    public ActionResult Update(Benefit entity)
    //    {
    //        try
    //        {
    //            if (ModelState.IsValid)
    //            {
    //                ManagerFactory.BenefitManager.Update(entity);

    //                return Json(new AJAXResponse { Message = Localized.Message("Update", MessageType.Success), Success = true, MustRedirect = false });
    //            }
    //            throw new BusinessException(Localized.Message("Model", MessageType.Error));
    //        }
    //        catch (BusinessException ex)
    //        {
    //            throw;
    //        }
    //        catch (Exception ex)
    //        {
    //            throw new Exception(Localized.Message("Exception", MessageType.Error));
    //        }
    //    }

    //    [AJAXExceptionHandler]
    //    public ActionResult Delete(Benefit entity)
    //    {
    //        try
    //        {
    //            ManagerFactory.BenefitManager.Delete(entity);

    //            return Json(new AJAXResponse { Message = Localized.Message("Delete", MessageType.Success), Success = true, MustRedirect = false });
    //        }
    //        catch (Exception ex)
    //        {
    //            throw new Exception(Localized.Message("Exception", MessageType.Error));
    //        }
    //    }
    }
}
